<?php
/**
 * Table Definition for user_group
 */

class Group_service extends Memcached_DataObject {
###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    public $__table = 'am_group_service';                          // table name
    public $id;                              // int(4)  primary_key not_null
    public $group_id;                      // int(4)   not_null
    public $type;                     // int(4)   not_null
    public $created_at;                   // datetime(255)
    public $updated_at;                   // timestamp(255)

    /* Static get */
    function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_service',$k,$v); }

    function &pkeyGet($kv) {
        return Memcached_DataObject::pkeyGet('Group_service', $kv);
    }
    /**
     * Verify Group Amway service
     *
     * @category Amway
     * @package  StatusNet
     * @author   thuclh <thuc.lehuy@gmail.com>
     * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
     * @link     http://status.net/
     */
    function is_group_amway($group_id) {
        $type = 'aw';
        $group = Group_service::pkeyGet(array('group_id'=>$group_id,'type'=>'aw'));
        return (is_null($group)) ? false : true;
    }
    /**
     * Verify Group Amway service
     *
     * @category Amway
     * @package  StatusNet
     * @author   thuclh <thuc.lehuy@gmail.com>
     * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
     * @link     http://status.net/
     */
    function add_group_amway($group_id) {
        $type = 'aw';
        $id = true;
        if(!common_is_amway_group($group_id)) {
            $group_service = new Group_service();
            $group_service->group_id = $group_id;
            $group_service->type = $type;
            $group_service->created_at = common_sql_now();
            $group_service->updated_at = common_sql_now();
            $id = $group_service->insert();
            if (!$id) {
                common_log_db_error($group_service, 'INSERT', __FILE__);
                $id = false;
            }
        }
        return $id;
    }
}
